//
//  DewResultViewController.m
//  UEAssistant
//
//  Created by mac on 2017/9/8.
//  Copyright © 2017年 youyixinxi. All rights reserved.
//

#import "DewResultViewController.h"
#import "TickersHeader.h"
#import "DeweightModel.h"
#import "SocketRocketUtility.h"
@interface DewResultViewController ()<UITableViewDataSource,UITableViewDelegate,FoldTickersSectionHeaderViewDelegate>{

    NSMutableArray                  *_headerDataSource;
    NSMutableArray                  *_cellDataSource;
    NSMutableArray                  *_prefixData;
    NSMutableArray                  *_paydOrNoPay;
}

@property (nonatomic, strong) UILabel           *waitLabel;
@property (nonatomic, strong) UITableView       *tableView;
@property (nonatomic, strong) NSDictionary      *foldInfoDic;/**< 存储开关字典 */
@property (nonatomic, assign) NSInteger         lastSection;//记录上次选中的cell
@property (nonatomic, strong) UIView            *statisticsView;
@property (nonatomic, strong) UIImageView       *seletImage;
@property (nonatomic, strong) UIButton          *selectButton;
@property (nonatomic, strong) UILabel           *selectAllLabel;
@property (nonatomic, strong) UILabel           *allMoneyLabel;
@property (nonatomic, strong) UILabel           *allMoneylabelSub;
@property (nonatomic, strong) UIButton          *payButton;
@property (nonatomic, strong) UIView            *coverView;
@property (nonatomic, strong) NSMutableArray    *orderIdsArr;
@property (nonatomic, strong) NSString          *orderIdString;
@property (nonatomic, assign) BOOL              hasOrderAtlestOne;
@property (nonatomic, strong) UILabel           *NaviTitle;
@property (nonatomic, strong) UIButton          *deweight_Now;
@property (nonatomic, strong) UIButton          *deweight_after;
@property (nonatomic, assign) BOOL              success_pre;
@property (nonatomic, assign) BOOL              success_deweight;
@property (nonatomic, strong) NSString          *UUID;
@property (nonatomic, strong) NSString          *dicIds;

@property (nonatomic, strong) NSString *loadingText;
@property (copy, nonatomic)NSString  *socketId;
@end

@implementation DewResultViewController

- (void)viewWillAppear:(BOOL)animated{
    
    [self.NaviTitle setHidden:NO];
}

- (void)viewWillDisappear:(BOOL)animated{
    
    [self.NaviTitle setHidden:YES];
    [[SocketRocketUtility instance] SRWebSocketClose];
}

-(void)loadView
{
    [super loadView];
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0 ,0 , self.view.frame.size.width, self.view.frame.size.height - 64)style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = RGB(247, 247, 247, 1);
    _tableView.separatorColor = [UIColor colorWithWhite:0.9 alpha:1];
    [self.view addSubview:_tableView];
    self.edgesForExtendedLayout=UIRectEdgeNone;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUserface];
    [self initDataSource];
    [self connectWebSocket];

}

- (void)initDataSource{
    
    _foldInfoDic = [NSMutableDictionary dictionary];
    _headerDataSource = [NSMutableArray array];
    _cellDataSource = [NSMutableArray array];
    _prefixData = [NSMutableArray array];
    _orderIdsArr = [NSMutableArray array];
    _paydOrNoPay = [NSMutableArray  array];
    _loadingText = @"";
}

- (void)initUserface{

    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar addSubview:self.NaviTitle];
    
    _tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
    _tableView.estimatedSectionHeaderHeight = 80;


}

#pragma mark -- 去重预处理和结果请求
//连接webSocket
- (void)connectWebSocket {
    [[SocketRocketUtility instance] SRWebSocketOpen];//打开soket
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(SRWebSocketDidOpen) name:@"kWebSocketDidOpenNote" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(SRWebSocketDidReceiveMsg:) name:@"kWebSocketdidReceiveMessageNote" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reconnectedFail) name:@"reconnectFailed" object:nil];
}

#pragma mark -- socket
- (void)SRWebSocketDidOpen {
    TGLog(@"开启成功");
    //在成功后需要做的操作。。。
    [LSProgressHUD showLoadingToView:self.navigationController.view];
    if (_UUID) {
        [[SocketRocketUtility instance] sendData:_UUID];
    }
}
- (void)reconnectedFail {
    [self.navigationController popViewControllerAnimated:YES];
    [self.waitLabel removeFromSuperview];
    [TopAlertView SetUpbackgroundColor:AlertRedColor andStayTime:2.0 andImageName:@"imagePlaceholder" andTitleStr:@"网络开小差了~" andTitleColor:[UIColor whiteColor] andCancel:NO];
}

- (void)SRWebSocketDidReceiveMsg:(NSNotification *)note {
    //收到服务端发送过来的消息
    NSString * message = note.object;
    if (message) {
        NSData* data = [message dataUsingEncoding:NSUTF8StringEncoding];
        id dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        //及时变换状态提示语
        TGLog(@"%@",dict);
        if ([dict[@"code"] integerValue] == 201) {
            
            _loadingText = dict[@"message"] == nil ? _loadingText:dict[@"message"];
            [LSProgressHUD hideForWindow];
            [LSProgressHUD hideForView:self.navigationController.view];
            [LSProgressHUD showWithMessage:_loadingText];
            
        }else if ([dict[@"code"] integerValue] == 202) {
            
            [LSProgressHUD hideForWindow];
            [TopAlertView SetUpbackgroundColor:AlertRedColor andStayTime:2.0 andImageName:@"imagePlaceholder" andTitleStr:dict[@"message"] andTitleColor:[UIColor whiteColor] andCancel:NO];
            [[SocketRocketUtility instance] SRWebSocketClose];
            [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
            
        }else if ([dict[@"code"] integerValue] == 200) {
                
            if ([dict[@"type"] integerValue] == 0) {
                //接收到socketId发去预处理请求
                _socketId = dict[@"result"][@"socketId"];
                [self testDeweightRequestWithSocketId:_socketId];
                
            }else if ([dict[@"type"] integerValue] == 5) {//预处理结果
                //收到返回预处理成功，刷新界面
                [self pretreatmentWithResult:(NSArray *)dict[@"result"]];
                
            }else if ([dict[@"type"] integerValue] == 8) {//去重结果
                //去重成功处理
                [[SocketRocketUtility instance] SRWebSocketClose];
                [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
                [TopAlertView SetUpbackgroundColor:mainColor andStayTime:2.0 andImageName:@"imagePlaceholder" andTitleStr:@"去重成功" andTitleColor:[UIColor whiteColor] andCancel:NO];
            }
            [LSProgressHUD hideForWindow];
        }
    }
}
//预处理
- (void)testDeweightRequestWithSocketId:(NSString *)socketId{
    [self.view addSubview:self.waitLabel];
    if ([self.docid containsString:@","]) {
        NSMutableArray *docIds = [NSMutableArray array];
        NSArray *suffixArr = [self.doc_namesuffix componentsSeparatedByString:@","];
        NSArray *tempArr = [self.docid componentsSeparatedByString:@","];
        [tempArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [docIds addObject:[NSString stringWithFormat:@"%@_%@",obj,suffixArr[idx]]];
        }];
        _dicIds = [docIds componentsJoinedByString:@","];
    }else{
        _dicIds = [NSString stringWithFormat:@"%@_%@",self.docid,self.doc_namesuffix];
    }
    NSDictionary *params = @{@"projectId":detailsModel.product_Id,
                             @"docIds":_dicIds,
                             @"sourceLanguageKey":detailsModel.sourceKey,
                             @"lockList":self.switchList,
                             @"minlength":self.minLength,
                             @"ifdupall":self.ifdupall,
                             @"mt":self.mt,
                             @"socketId":socketId};
    [AvailableNetWorking postWithUrl:fileDeWeight_connector params:params successHandler:^(id responseObject) {
        
        NSLog(@"respond == %@",responseObject);
        if ([responseObject[@"code"] integerValue] == 200) {
            _UUID = responseObject[@"result"];
        }else{
            [[SocketRocketUtility instance] SRWebSocketClose];
            [self.navigationController popViewControllerAnimated:YES];
            [self.waitLabel removeFromSuperview];
            [TopAlertView SetUpbackgroundColor:AlertRedColor andStayTime:2.0 andImageName:@"imagePlaceholder" andTitleStr:responseObject[@"message"] andTitleColor:[UIColor whiteColor] andCancel:NO];
        }
        [LSProgressHUD hideForView:self.navigationController.view];
    } falureHandler:^(NSError *error) {
        [[SocketRocketUtility instance] SRWebSocketClose];
        [LSProgressHUD hideForWindow];
        [self.navigationController popViewControllerAnimated:YES];
        [self.waitLabel removeFromSuperview];
        
    }];
}
//预处理成功之后的操作，获取列表，刷新。。。
- (void)pretreatmentWithResult:(NSArray *)result {
    
    [_headerDataSource removeAllObjects];
    self.NaviTitle.text = @"去重结果";
    _loadingText = @"";
    _prefixData = [NSMutableArray arrayWithArray:result];
    for (int i = 0; i < result.count; i++) {
        NSDictionary *dic = result[i];
        DeweightModel *model = [[DeweightModel alloc]initWithDictionary:dic];
        [_headerDataSource addObject:model];
    }
    _tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.frame = CGRectMake(0 ,0 , self.view.frame.size.width, self.view.frame.size.height - 90*Radio);
    [self.waitLabel removeFromSuperview];
    [self.tableView reloadData];
    [self createOtherUserFaceAfterPostSuccess];
}

#pragma mark -- Event

- (void)deweightButtonCliced{
    
    NSInteger selecteCount = 0;
    NSInteger no_segCount = 0;
    NSInteger dup_segCount = 0;
    NSInteger mt_segCount = 0;
    NSInteger selfpre_segCount = 0;
    NSInteger sharedpre_SegCount = 0;
    
    for (DeweightModel *model in _headerDataSource) {
        if (model.isSelected) {
            no_segCount += model.no_SegCount;
            dup_segCount += model.dup_SegCount;
            mt_segCount += model.mt_SegCount;
            selfpre_segCount += model.selfpre_SegCount;
            sharedpre_SegCount += model.sharedpre_SegCount;
            selecteCount += 1;
        }
    }
    if (selecteCount == 0) {
        [TopAlertView SetUpbackgroundColor:AlertRedColor andStayTime:2.0 andImageName:@"imagePlaceholder" andTitleStr:@"请选择需要去重的文件!" andTitleColor:[UIColor whiteColor] andCancel:NO];
        return;
    }
    [LSProgressHUD showLoadingToView:self.navigationController.view];
    NSString *rowCount = [NSString stringWithFormat:@"%zd",no_segCount+dup_segCount+mt_segCount+selfpre_segCount+sharedpre_SegCount];

    NSDictionary *params = @{@"projectId":detailsModel.product_Id,
                             @"docIds":self.docid,
                             @"lockList":@"33111",
                             @"uuid":_UUID,
                             @"socketId":_socketId,
                             @"rowCount":rowCount
                             };
    [AvailableNetWorking postWithUrl:fileDeweight_END_connector params:params successHandler:^(id responseObject) {
       
        if ([responseObject[@"code"] integerValue] == 200) {//            //查询最终去重结果

        }else{
            [TopAlertView SetUpbackgroundColor:AlertRedColor andStayTime:2.0 andImageName:@"imagePlaceholder" andTitleStr:responseObject[@"message"] andTitleColor:[UIColor whiteColor] andCancel:NO];
        }
//        [LSProgressHUD hideForView:self.navigationController.view];
    } falureHandler:^(NSError *error) {
    }];
}


//暂不去重
- (void)notDeweightButtonCliced{
    //返回
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark -- UITableViewDataSource,UITableViewDelegate
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.backgroundColor = RGB(250, 250, 250, 1);
    cell.textLabel.textColor = RGB(51, 51, 51, 1);
    cell.detailTextLabel.textColor = RGB(51, 51, 51, 1);
    cell.textLabel.font = [UIFont systemFontOfSize:FLEXIBLE(15)];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:FLEXIBLE(15)];
    cell.textLabel.text = [self judgeDeweightTypeWithExt:_prefixData[indexPath.section][@"costList"][indexPath.row][@"type"]];
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@马刀",_prefixData[indexPath.section][@"costList"][indexPath.row][@"money"]];
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSString *key = [NSString stringWithFormat:@"%d", (int)section];
    BOOL folded = [[_foldInfoDic objectForKey:key] boolValue];
    if (folded) {
        
        if ([_prefixData[section][@"costList"] isEqual:[NSNull null]]) {
            return 0;
        }
        return ((NSArray *)_prefixData[section][@"costList"]).count;
    }
    return 0;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _headerDataSource.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 55 + [self autoCalculateWidthOrHeight:MAXFLOAT width:Screen_Width-120 fontsize:16 content:((DeweightModel *)_headerDataSource[section]).doc_name];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.001f;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    TickersHeader *headerView = [[TickersHeader alloc] initWithReuseIdentifier:@"header"];
    NSString *money;
    if ([[NSString stringWithFormat:@"%@",((DeweightModel *)_headerDataSource[section]).totalMoney] isEqualToString:@"(null)"]) {
        money = @"0.00";
    }else{
        money = ((DeweightModel *)_headerDataSource[section]).totalMoney;
    }
    [headerView setFoldSectionHeaderViewWithTitle:((DeweightModel *)_headerDataSource[section]).doc_name detail:money section:section canFold:YES height:[self autoCalculateWidthOrHeight:MAXFLOAT width:Screen_Width-120 fontsize:16 content:((DeweightModel *)_headerDataSource[section]).doc_name]];
    
    //处理折叠协议
    headerView.delegate = self;
    headerView.typeImage.image = [UIImage imageNamed:[self stringReplaceString:_prefixData[section][@"ext"]]];
    NSString *key = [NSString stringWithFormat:@"%d", (int)section];
    BOOL folded = [[_foldInfoDic valueForKey:key] boolValue];
    headerView.fold = folded;
    
    //处理选中订单
    if (((DeweightModel *)_headerDataSource[section]).isSelected) {
        headerView.seletImage.image = [UIImage imageNamed:@"选中"];
        _lastSection = section;
        
    }else{
        headerView.seletImage.image = [UIImage imageNamed:@"选择"];
    }
    
    //支付栏状态改变
    __block float totelMoney = 0.00;
    __block int   index      = 0;
    [_headerDataSource enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if (((DeweightModel *)obj).isSelected) {
            totelMoney += [((DeweightModel *)obj).totalMoney floatValue];
            index += 1;
        }
    }];
    
    _allMoneylabelSub.attributedText = [self attributeStringWith:[NSString stringWithFormat:@"%.2f",totelMoney]];
    [_payButton setTitle:[NSString stringWithFormat:@"支付(%d)",index] forState:UIControlStateNormal];
    detailsModel.needPay = [NSString stringWithFormat:@"%.2f",totelMoney];
    
    return headerView;
}

#pragma mark sectionHeader的展开和选中协议
- (void)foldHeaderInSection:(NSInteger)SectionHeader {
    
    NSString *key = [NSString stringWithFormat:@"%d",(int)SectionHeader];
    BOOL folded = [[_foldInfoDic objectForKey:key] boolValue];
    NSString *fold = folded ? @"0" : @"1";
    [_foldInfoDic setValue:fold forKey:key];
    [self.tableView reloadData];
    
}

- (void)selectTikkets:(UIButton *)sender section:(NSInteger)sectionHeader{
    
    if (((DeweightModel *)_headerDataSource[sectionHeader]).isSelected == NO) {
        ((DeweightModel *)_headerDataSource[sectionHeader]).isSelected = YES;
    }
    else{
        ((DeweightModel *)_headerDataSource[sectionHeader]).isSelected = NO;
    }
//    NSInteger notSelectedCount = 0;
//    for (DeweightModel *model in _headerDataSource) {
//        if (model.isSelected == NO) {
//            notSelectedCount += 1;
//        }
//    }
//    if (notSelectedCount == 0) {
//        //如果列表中全部都选中了，则让全选按钮自动选上
//        _selectButton.selected = NO;
//        [self selectAllBtCliced:_selectButton];
//    }else{
//        _selectButton.selected = YES;
//        [self selectAllBtCliced:_selectButton];
//    }
    [self.tableView reloadData];
}

#pragma mark -- 全选
- (void)selectAllBtCliced:(UIButton *)sender{
    
    sender.selected = !sender.selected;
    if (sender.selected) {
        _seletImage.image = [UIImage imageNamed:@"选中"];
        [_headerDataSource enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([((DeweightModel *)obj).totalMoney doubleValue] != 0) {
                ((DeweightModel *)obj).isSelected = YES;
            }
        }];
        
    }else{
        _seletImage.image = [UIImage imageNamed:@"选择"];
        [_headerDataSource enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            ((DeweightModel *)obj).isSelected = NO;
        }];
    }
    [self.tableView reloadData];
}


#pragma mark -- 计算宽窄的函数
-(float)autoCalculateWidthOrHeight:(float)height
                             width:(float)width
                          fontsize:(float)fontsize
                           content:(NSString*)content
{
    //计算出rect
    CGRect rect = [content boundingRectWithSize:CGSizeMake(width, height)
                                        options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                     attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontsize]} context:nil];
    
    //判断计算的是宽还是高
    if (height == MAXFLOAT) {
        return rect.size.height;
    }
    else
        return rect.size.width;
}


#pragma private
- (NSMutableAttributedString *)attributeStringWith:(NSString *)money {
    NSString *str = [NSString stringWithFormat:@"%@马刀", money];
    NSMutableAttributedString *ats = [[NSMutableAttributedString alloc] initWithString:str];
    NSRange range = [str rangeOfString:money];
    [ats setAttributes:@{NSForegroundColorAttributeName:RGB(232, 78, 81, 1),NSFontAttributeName:[UIFont systemFontOfSize:14]} range:range];
    return ats;
}

- (NSMutableAttributedString *)attributeStringWith:(NSString *)money string:(NSString *)string{
    NSString *str = [NSString stringWithFormat:@"%@%@", money,string];
    NSMutableAttributedString *ats = [[NSMutableAttributedString alloc] initWithString:str];
    NSRange range = [str rangeOfString:string];
    [ats setAttributes:@{NSForegroundColorAttributeName:RGB(232, 78, 81, 1),NSFontAttributeName:[UIFont systemFontOfSize:FLEXIBLE(15)]} range:range];
    return ats;
}

- (NSString *)stringReplaceString:(NSString *)string{
    
    if ([string isEqualToString:@"dwg"] || [string isEqualToString:@"dxf"]) {
        
        return @"CAD";
    }
    else if ([string isEqualToString:@"doc"] || [string isEqualToString:@"docx"] || [string isEqualToString:@"rtf"]){
        
        return @"word";
    }
    else if ([string isEqualToString:@"xls"] || [string isEqualToString:@"xlsx"]){
        
        return @"Exel";
    }
    else if ([string isEqualToString:@"ppt"] || [string isEqualToString:@"pptx"]){
        
        return @"ppt";
    }
    else if ([string isEqualToString:@"vsdx"]){
        
        return @"vsdx";
    }
    else if ([string isEqualToString:@"sdlxliff"]){
        
        return @"sdlxliff";
    }
    else{
        
        return @"pdf";
    }
}

- (NSString *)judgeDeweightTypeWithExt:(NSString *)ext{

    if ([ext isEqualToString:@"qc"]) {
        
        return @"文件去重";
    }
    if ([ext isEqualToString:@"gx"]) {
        return @"文件解析";
    }
    return @"";
}


- (void)createOtherUserFaceAfterPostSuccess{
    
    _statisticsView = [[UIView alloc]initWithFrame:CGRectMake(0, Screen_Height-90*Radio-64, Screen_Width, 40*Radio)];
    _statisticsView.backgroundColor = [UIColor whiteColor];
    _statisticsView.layer.shadowColor = [UIColor grayColor].CGColor;
    _statisticsView.layer.shadowOffset = CGSizeMake(0, -0.7);
    _statisticsView.layer.shadowOpacity = 0.2;
    _statisticsView.layer.shadowRadius = 1.0;
    [self.view addSubview:_statisticsView];
    
    _seletImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    _seletImage.backgroundColor = [UIColor clearColor];
    _seletImage.center = CGPointMake(25, 40*Radio/2);
    _seletImage.image = [UIImage imageNamed:@"选择"];
    [_statisticsView addSubview:_seletImage];
    
    _selectAllLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 30, 20)];
    _selectAllLabel.center = CGPointMake(60, 40*Radio/2);
    _selectAllLabel.backgroundColor = [UIColor clearColor];
    _selectAllLabel.font = [UIFont systemFontOfSize:FLEXIBLE(14)];
    _selectAllLabel.textColor = RGB(51, 51, 51, 1);
    _selectAllLabel.text = @"全选";
    [_statisticsView addSubview:_selectAllLabel];
    
    _selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _selectButton.frame = CGRectMake(0, 0, 40, 40);
    _selectButton.center = CGPointMake(25, 40*Radio/2);
    _selectButton.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
    [_selectButton addTarget:self action:@selector(selectAllBtCliced:) forControlEvents:UIControlEventTouchUpInside];
    [_statisticsView addSubview:_selectButton];
    
    _allMoneyLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 40, 20)];
    _allMoneyLabel.center = CGPointMake(self.view.center.x-30*Radio, 40*Radio/2);
    _allMoneyLabel.backgroundColor = [UIColor clearColor];
    _allMoneyLabel.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _allMoneyLabel.textColor = RGB(124, 124, 124, 1);
    _allMoneyLabel.text = @"合计：";
    [_statisticsView addSubview:_allMoneyLabel];
    
    _allMoneylabelSub = [[UILabel alloc]initWithFrame:CGRectMake(_allMoneyLabel.frame.origin.x+_allMoneyLabel.frame.size.width, _allMoneyLabel.frame.origin.y, 100*Radio, 20)];
    _allMoneylabelSub.backgroundColor = [UIColor clearColor];
    _allMoneylabelSub.font = [UIFont systemFontOfSize:FLEXIBLE(15)];
    _allMoneylabelSub.textColor = RGB(51, 51, 51, 1);
    _allMoneylabelSub.attributedText = [self attributeStringWith:@"0.00"];
    [_statisticsView addSubview:_allMoneylabelSub];
    
    [self.view addSubview:self.deweight_after];
    [self.view addSubview:self.deweight_Now];
}


#pragma mark -- getter
- (UILabel *)NaviTitle{
    
    if (!_NaviTitle) {
        _NaviTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 20)];
        _NaviTitle.center = CGPointMake(self.view.center.x, 20);
        _NaviTitle.backgroundColor = [UIColor clearColor];
        _NaviTitle.text = @"去重分析中";
        _NaviTitle.textAlignment = NSTextAlignmentCenter;
        _NaviTitle.textColor = [UIColor colorWithHexString:@"#333333"];
    }
    return _NaviTitle;
}

- (UILabel *)waitLabel{
    
    if (!_waitLabel) {
        _waitLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 20)];
        _waitLabel.center = CGPointMake(self.view.center.x, self.view.center.y);
        _waitLabel.backgroundColor = [UIColor clearColor];
        _waitLabel.text = @"我正在努力统计...";
        _waitLabel.textColor = RGB(111, 111, 111, 1);
        _waitLabel.font = [UIFont systemFontOfSize:15];
        _waitLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _waitLabel;
}


- (UIButton *)deweight_Now{
    
    if (!_deweight_Now) {
        
        _deweight_Now = [UIButton buttonWithType:UIButtonTypeSystem];
        _deweight_Now.frame = CGRectMake(Screen_Width/2, Screen_Height - 50*Radio-64, Screen_Width/2, 50*Radio);
        _deweight_Now.backgroundColor = RGB(39, 181, 238, 1);
        [_deweight_Now setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_deweight_Now setTitle:@"立即去重" forState:UIControlStateNormal];
        [_deweight_Now addTarget:self action:@selector(deweightButtonCliced) forControlEvents:UIControlEventTouchUpInside];
        _deweight_Now.titleLabel.font = [UIFont systemFontOfSize:FLEXIBLE(16)];
    }
    return _deweight_Now;
}

- (UIButton *)deweight_after{
    
    if (!_deweight_after) {
        
        _deweight_after = [UIButton buttonWithType:UIButtonTypeSystem];
        _deweight_after.frame = CGRectMake(0, Screen_Height - 50*Radio-64, Screen_Width/2, 50*Radio);
        _deweight_after.backgroundColor = RGB(47, 155, 211, 1);
        [_deweight_after setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_deweight_after setTitle:@"暂不去重" forState:UIControlStateNormal];
        [_deweight_after addTarget:self action:@selector(notDeweightButtonCliced) forControlEvents:UIControlEventTouchUpInside];
        _deweight_after.titleLabel.font = [UIFont systemFontOfSize:FLEXIBLE(16)];
    }
    return _deweight_after;
}


//废弃方法,去重预处理查询结果
- (void)getDeweightResultWithUUID:(NSString *)uuid{
    
    _UUID = uuid;
    NSDictionary *params = @{@"projectId":detailsModel.product_Id,
                             @"uuid":uuid};
    [AvailableNetWorking postWithUrl:fileDeweightResult_connector params:params successHandler:^(id responseObject) {
        
        if ([responseObject[@"code"] integerValue] == 200) {
            
            [_headerDataSource removeAllObjects];
            _success_pre = YES;
            self.NaviTitle.text = @"去重结果";
            //            NSLog(@"去重结果 == %@",responseObject);
            
            _prefixData = responseObject[@"fileList"];
            for (int i = 0; i < ((NSArray *)(responseObject[@"fileList"])).count; i++) {
                
                NSDictionary *dic = responseObject[@"fileList"][i];
                DeweightModel *model = [[DeweightModel alloc]initWithDictionary:dic];
                [_headerDataSource addObject:model];
            }
            _tableView.backgroundColor = [UIColor whiteColor];
            self.tableView.frame = CGRectMake(0 ,0 , self.view.frame.size.width, self.view.frame.size.height - 90*Radio);
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [LSProgressHUD hiddenLoading:self.parentViewController.view];
                [self.waitLabel removeFromSuperview];
                [self.tableView reloadData];
                [self createOtherUserFaceAfterPostSuccess];
            });
            return ;
        }else{
            
            NSLog(@"正在进行预处理...");
        }
        
    } falureHandler:^(NSError *error) {
        
        [self.navigationController popViewControllerAnimated:YES];
        [LSProgressHUD hiddenLoading:self.view];
        [self.waitLabel removeFromSuperview];
        
    }];
}


- (void)getDeweightEndResult{
    
    NSDictionary *params = @{@"projectId":detailsModel.product_Id,
                             @"uuid":_UUID};
    [AvailableNetWorking postWithUrl:fileDeweightResult_END_connector params:params successHandler:^(id responseObject) {
        
        NSLog(@"respond == %@",responseObject);
        
        if ([responseObject[@"code"] integerValue] == 200) {
            
            _success_deweight = YES;
            [LSProgressHUD hiddenLoading:self.view];
            [self.navigationController popViewControllerAnimated:YES];
            [TopAlertView SetUpbackgroundColor:mainColor andStayTime:2.0 andImageName:@"imagePlaceholder" andTitleStr:@"去重成功" andTitleColor:[UIColor whiteColor] andCancel:NO];
        }
        else{
            NSLog(@"正在去重...");
        }
        
    } falureHandler:^(NSError *error) {
        
        _success_deweight = YES;
        [LSProgressHUD hiddenLoading:self.view];
        
    }];
}
@end
